(function($){

$(function(){
	$('.top-cart').mouseenter(function(){
		$('.shopping-cart').addClass('cart-hover')
		$('.top-car-list').stop(true).eq($('.shopping-cart').index(this)).animate({height:83,paddingTop:15})
	});
	$('.top-cart').mouseleave(function(){
		$('.shopping-cart').removeClass('cart-hover')
		$('.top-car-list').stop().eq($('.shopping-cart').index(this)).animate({height:0,paddingTop:0})
	})
	
	/////////////////////////////////////////////
	//nav
	$('.nav .n1 ').mouseover(function(){
//		console.log($('this').index()+'----')
//		console.log($('.nav .n1 ').index(this))
		$(".nav-content").css({display:'block'})
		$('.nav1 ').stop(true).animate({height:229},'fast');
		$('.nav1').css({display:'none'})
		
		$('.nav1').eq($('.nav .n1 ').index(this)).css({display:'block'})
		
	})
	
	$('.nav1 ').mouseover(function(){
		
		$('.nav1 ').stop(true).animate({height:229},'fast');
		$('.nav1').css({display:'none'})
		$('.nav1').eq($('.nav1').index(this)).css({display:'block'})
		
	})
	
	$('.nav .n1 ').mouseout(function(){
		
		$('.nav1 ').animate({height:0},'fast');
		//$(".nav-content").css({display:'none'})
	})
	
	$('.nav1 ').mouseout(function(){
		
		$('.nav1 ').animate({height:0},'fast');
		//$(".nav-content").css({display:'none'})
	})
	////////////////////////////////////////////////////
	$('.ipt').blur(function(){
		var arr=[];
		$.ajax({
			url:'http://search.mi.com/search/expand?keyword=%E5%B0%8F%E7%B1%B3&',
			beforeSend:function(xhr){
				//console.log('beforeSend')
			},
			dataFilter:function(data){
				//console.log('dataFilter')
				return data;
			},
			success:function(data){
				//console.log('success')
				arr=eval(data)
				console.log(arr)
			},
			complete:function(xhr,ts){
				//console.log('complete')
				
			},
			dataType:'jsonp',
			jsonp:'jsonpcallback',
			
			//jsonpcallback;'sData'
		})
	})
	
	function sData(data) {
				//console.log(data.s)
				var oList = document.getElementById('list');
				var html = ''
				if (data.s.length > 0) {
					for (var i = 0; i < data.s.length; i++) {
						html += '<li><a href="https://www.baidu.com/s?wd=' + data.s[i] + '" target="_blank">' + data.s[i] + '</a></li>'
					}
					oList.style.display = 'block';
					oList.innerHTML = html;
				}else{
					oList.style.display = 'none';
				}
			}
	////////////////////////////////////////////////////
	//switchCard
	$('.list li').mouseover(function(){
		$(' .list li').removeClass('mouse_over_style');
		$('.list  li').eq($(' .list li').index(this)).addClass('mouse_over_style');
		$('.box_list').css('display','none');
		$('.box_list').eq($(' .list li').index(this)).css('display','block');
		
	});
	$('.list li').mouseout(function(){
		$('li').eq($('.list li').index(this)).removeClass('mouse_over_style');
		$('.box_list').eq($('.list li').index(this)).css('display','none');
	});
	$('.box_list').mouseover(function(){
		$('.box_list').eq($('.box_list').index(this)).css('display','block');
		$('.list li').eq($('.box_list').index(this)).addClass('mouse_over_style');
	});
	$('.bgbox').mouseout(function(){
		$('.list li').removeClass('mouse_over_style');
		$('.box_list').css('display','none');
	});
		
		
	///////////////////////////////////////////////////////	
	//轮播图
	var iCurrent=0,
		timer=null;
	//移入移出	
	$('pic-list li').hover(function(){
		clearInterval(timer);
		
	},function(){
		autoMove()
	})
	//往左运动
	$('.left-btn').click(function(){
		iCurrent--;
		console.log(iCurrent+"l")
		move();
		
	})
	//往右运动
	$('.right-btn').click(function(){
		
		iCurrent++;
		console.log(iCurrent+"r")
		move();
		
	})
	//自动运动
	autoMove()
	function autoMove(){
		timer=setInterval(function(){
			move()
			iCurrent++
		},3000)
	}
	//划过pic-list
	$('.pic-list ').on('mouseover','li',function(){
		var iIndex=$(this).index();
		console.log(this)
		if(iIndex===iCurrent){
			return;
		}
		iCurrent=iIndex;
		move()
	})
	function move(){
		//console.log("--ii-"+iCurrent)
//		console.log("----"+$('.pic-list li').length)
		if(iCurrent>=$('.pic-list li').length-1){
			iCurrent=0;
		}
		if(iCurrent<0){
			iCurrent=$('.pic-list li').length-1;
		}
		
		$('.pic-box li').stop(true).animate({
			opacity:0
		})
		.eq(iCurrent).stop().animate({opacity:1})
		
		$('.pic-list li').removeClass('over').eq(iCurrent).addClass('over')
		
	}
	
	
	
});		
		
})(jQuery)